<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Fluency Questionnaire Survey - Learning Experience</title>
    <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
    <style>
      body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
        background-color: #fff;
        color: #333;
      }

      .dark body {
        background-color: #1a1a1a;
        color: #f5f5f5;
      }

      /* 进度条样式 */
      .progress-container {
        height: 4px;
        width: 100%;
        background-color: #f0f0f0;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
      }

      .progress-bar {
        height: 100%;
        background-color: #007aff;
        width: 35%; /* 8步，第3步 */
      }

      .dark .progress-container {
        background-color: #333;
      }

      /* 顶部导航 */
      .top-nav {
        padding: 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .back-btn {
        color: #007aff;
        font-size: 1.25rem;
        cursor: pointer;
      }

      /* 内容区域 */
      .content {
        max-width: 500px;
        margin: 0 auto;
        padding: 1rem;
      }

      /* 选择卡片样式 */
      .experience-card {
        padding: 1.5rem;
        border-radius: 12px;
        border: 1px solid #e5e7eb;
        margin-bottom: 1rem;
        cursor: pointer;
        transition: all 0.2s;
        display: block;
        text-align: center;
        font-size: 16px;
        line-height: 1.5;
      }

      .experience-card:hover,
      .experience-card.selected {
        border-color: #007aff;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
      }

      .experience-card.selected {
        background-color: rgba(0, 122, 255, 0.1);
      }

      /* 按钮样式 */
      .btn-primary {
        background-color: #007aff;
        color: white;
        padding: 0.75rem 1.5rem;
        border-radius: 10px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        width: 100%;
        justify-content: center;
        border: none;
      }

      .btn-primary:hover {
        background-color: #0062cc;
      }

      .btn-primary:disabled {
        background-color: #c7c7cc;
        cursor: not-allowed;
      }

      /* 适配黑暗模式 */
      .dark .experience-card {
        border-color: #4a5568;
        background-color: #2d3748;
      }

      .dark .experience-card:hover,
      .dark .experience-card.selected {
        border-color: #0a84ff;
      }

      .dark .experience-card.selected {
        background-color: rgba(10, 132, 255, 0.2);
      }

      /* 主题切换按钮 */
      .theme-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #007aff;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        z-index: 1000;
      }

      .theme-toggle:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
      }

      .nav-progress-container {
        display: flex;
        align-items: center;
        margin-bottom: 40px;
        gap: 15px;
      }

      .back-button {
        width: 30px;
        height: 30px;
        border: none;
        background: none;
        cursor: pointer;
        color: #2b85e4;
        font-size: 20px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .back-button svg {
        width: 20px;
        height: 20px;
        fill: currentColor;
      }

      .progress-bar {
        flex: 1;
        height: 6px;
        width: 423px;
        background-color: #e0e0e0;
        border-radius: 3px;
      }

      .progress {
        height: 100%;
        width: 36.63%;
        background-color: #2b85e4;
        border-radius: 3px;
      }
    </style>
    <script>
      // 检查深色模式
      function checkDarkMode() {
        if (
          localStorage.getItem('darkMode') === 'true' ||
          (localStorage.getItem('darkMode') === null && window.matchMedia('(prefers-color-scheme: dark)').matches)
        ) {
          document.documentElement.classList.add('dark')
          return true
        }
        return false
      }

      // 切换深色/浅色模式
      function toggleDarkMode() {
        if (document.documentElement.classList.contains('dark')) {
          document.documentElement.classList.remove('dark')
          localStorage.setItem('darkMode', 'false')
          document.getElementById('theme-icon').className = 'fas fa-moon'
        } else {
          document.documentElement.classList.add('dark')
          localStorage.setItem('darkMode', 'true')
          document.getElementById('theme-icon').className = 'fas fa-sun'
        }
      }

      // 当DOM加载完成
      document.addEventListener('DOMContentLoaded', function () {
        const isDark = checkDarkMode()
        document.getElementById('theme-icon').className = isDark ? 'fas fa-sun' : 'fas fa-moon'

        // 处理经历选择
        const experienceCards = document.querySelectorAll('.experience-card')

        // 恢复之前选中的状态
        const savedExperience = localStorage.getItem('learningExperience')
        if (savedExperience) {
          experienceCards.forEach(card => {
            if (card.getAttribute('data-value') === savedExperience) {
              card.classList.add('selected')
            }
          })
        }

        experienceCards.forEach(card => {
          card.addEventListener('click', function () {
            // 移除之前选中的卡片
            experienceCards.forEach(c => c.classList.remove('selected'))
            // 选中当前卡片
            this.classList.add('selected')

            // 获取选中的选项
            const selectedCard = document.querySelector('.experience-card.selected')
            if (selectedCard) {
              const learningExperience = selectedCard.getAttribute('data-value')

              // 获取页面标题和当前页面名称
              const pageTitle = document.querySelector('.text-3xl').textContent.trim()
              const pageName = window.location.pathname.split('/').pop().split('.')[0]
              const selectedText = selectedCard.textContent.trim()

              // 创建数据对象
              const data = {
                title: pageTitle,
                value: selectedText,
                experience: learningExperience,
              }

              // 以JSON格式存储到localStorage
              localStorage.setItem(pageName, JSON.stringify(data))

              // 保留原有存储方式，以保证兼容性
              localStorage.setItem('learningExperience', learningExperience)

              // 跳转到下一个页面
              window.location.href = 'speakingCan.html'
            }
          })
        })
      })

      // 移除 continueNext 函数，因为点击卡片直接跳转
      // function continueNext() {
      //   // 获取选中的选项
      //   const selectedCard = document.querySelector('.experience-card.selected');
      //   if (selectedCard) {
      //     const learningExperience = selectedCard.getAttribute('data-value');

      //     // 存储选择的学习经历
      //     localStorage.setItem('learningExperience', learningExperience);

      //     // 跳转到下一个页面
      //     window.location.href = 'speakingCan.html';
      //   }
      // }
    </script>
  </head>
  <body>
    <!-- 主内容区 -->
    <div class="content">
      <div class="nav-progress-container">
        <button class="back-button" onclick="window.location.href='/howDid.html'">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
          </svg>
        </button>
        <div class="progress-bar">
          <div class="progress"></div>
        </div>
      </div>
      <!-- 页面标题 -->
      <div class="flex justify-center">
        <h1 class="w-96 text-3xl text-[#0B4983] text-center font-bold mb-6 dark:text-blue-400">
          How would you describe your previous English learning experiences?
        </h1>
      </div>
      <!-- 学习经历选择 -->
      <div class="space-y-4 mb-8">
        <div class="experience-card" data-value="too_expensive">
          It was too expensive, and I didn't want to spend that much money.
        </div>

        <div class="experience-card" data-value="time_dedication">
          I struggled to dedicate time and couldn't continue.
        </div>

        <div class="experience-card" data-value="speaking_anxiety">
          I didn't want to practice speaking in front of others.
        </div>

        <div class="experience-card" data-value="no_personalization">There wasn't a personalized program for me.</div>

        <div class="experience-card" data-value="schedule_mismatch">My schedule didn't match with my teacher's.</div>

        <div class="experience-card" data-value="want_improvement">I made progress but want to improve further.</div>
      </div>

      <!-- 下一步按钮 -->
      <!-- 移除下一步按钮，因为点击卡片直接跳转 -->
      <!-- <button id="next-button" class="btn-primary" disabled onclick="continueNext()">
        下一步 <i class="fas fa-arrow-right ml-2"></i>
      </button> -->
    </div>

    <!-- 主题切换 -->
    <div class="theme-toggle" onclick="toggleDarkMode()">
      <i id="theme-icon" class="fas fa-moon"></i>
    </div>

    <script>
      // 初始化检查主题模式
      document.addEventListener('DOMContentLoaded', checkDarkMode)
    </script>
  </body>
</html>
